#!/bin/bash

# This file is for testing the Grades.jar file.
#
# The Grades.jar file accepts two parameters, both are taken as percentage
# scores.
#
# The course grade is computed as [(0.6*exam) + (0.4*practical)]
#
# Combined combined scores less than 50 is fail.                             [x]
# An exam score less than 40 (regardless of practical) is Component Fail.    [x]
# An practical score less than 40 (regardless of exam) is Component Fail.    [x]
# Combined Scores  >= 50 and <= 80 is Pass.                                  [x]
# Combined Scores > 80 and <= 100 is pass with discinction.                  [x]
# All other inputs produce Invalid Input.                                    [x]

GRADESFILE=Grades.jar

echo ""

# Test Case 1
INPUT="39 100"
EXPECTED="Component Fail"
RESULT=`java -jar $GRADESFILE $INPUT`
if [ "$EXPECTED" == "$RESULT" ]; then
    CASESTATUS="Passed."
else
    CASESTATUS="Failed."
fi

echo "+--------------------------------------"
echo "| TEST CASE ONE - EXAM < 40, PRAC > 40 "
echo "+--------------------------------------"
echo "| INPUT: $INPUT                        "
echo "| EXPECTED OUTPUT: $EXPECTED           "
echo "| ACTUAL OUTPUT: ${RESULT/$'\n'/}      "
echo "+--------------------------------------"
echo "|               TEST CASE: $CASESTATUS "
echo "+--------------------------------------"
echo ""


# Test Case 2
INPUT="100 39"
EXPECTED="Component Fail"
RESULT=`java -jar $GRADESFILE $INPUT`
if [ "$EXPECTED" == "$RESULT" ]; then
    CASESTATUS="Passed."
else
    CASESTATUS="Failed."
fi

echo "+--------------------------------------"
echo "| TEST CASE TWO - EXAM > 40, PRAC < 40 "
echo "+--------------------------------------"
echo "| INPUT: $INPUT                        "
echo "| EXPECTED OUTPUT: $EXPECTED           "
echo "| ACTUAL OUTPUT: ${RESULT/$'\n'/}      "
echo "+--------------------------------------"
echo "|               TEST CASE: $CASESTATUS "
echo "+--------------------------------------"
echo ""

# Test Case 3
INPUT="49 49"
EXPECTED="Fail"
RESULT=`java -jar $GRADESFILE 49 49`
if [ "$EXPECTED" == "$RESULT" ]; then
    CASESTATUS="Passed."
else
    CASESTATUS="Failed."
fi

echo "+--------------------------------------"
echo "| TEST CASE THREE - COMBINED < 50      "
echo "+--------------------------------------"
echo "| INPUT: $INPUT                        "
echo "| EXPECTED OUTPUT: $EXPECTED           "
echo "| ACTUAL OUTPUT: ${RESULT/$'\n'/}      "
echo "+--------------------------------------"
echo "|               TEST CASE: $CASESTATUS "
echo "+--------------------------------------"
echo ""

# Test Case 4
INPUT="50 50"
EXPECTED="Pass"
RESULT=`java -jar $GRADESFILE $INPUT`
if [ "$EXPECTED" == "$RESULT" ]; then
    CASESTATUS="Passed."
else
    CASESTATUS="Failed."
fi

echo "+--------------------------------------"
echo "| TEST CASE FOUR - COMBINED = 50       "
echo "+--------------------------------------"
echo "| INPUT: $INPUT                        "
echo "| EXPECTED OUTPUT: $EXPECTED           "
echo "| ACTUAL OUTPUT: ${RESULT/$'\n'/}      "
echo "+--------------------------------------"
echo "|               TEST CASE: $CASESTATUS "
echo "+--------------------------------------"
echo ""

# Test Case 5
INPUT="79 79"
EXPECTED="Pass"
RESULT=`java -jar $GRADESFILE $INPUT`
if [ "$EXPECTED" == "$RESULT" ]; then
    CASESTATUS="Passed."
else
    CASESTATUS="Failed."
fi

echo "+--------------------------------------"
echo "| TEST CASE FIVE - COMBINED = 79       "
echo "+--------------------------------------"
echo "| INPUT: $INPUT                        "
echo "| EXPECTED OUTPUT: $EXPECTED           "
echo "| ACTUAL OUTPUT: ${RESULT/$'\n'/}      "
echo "+--------------------------------------"
echo "|               TEST CASE: $CASESTATUS "
echo "+--------------------------------------"
echo ""

# Test Case 6
INPUT="80 80"
EXPECTED="Pass"
RESULT=`java -jar $GRADESFILE $INPUT`
if [ "$EXPECTED" == "$RESULT" ]; then
    CASESTATUS="Passed."
else
    CASESTATUS="Failed."
fi

echo "+--------------------------------------"
echo "| TEST CASE SIX - COMBINED = 80        "
echo "+--------------------------------------"
echo "| INPUT: $INPUT                        "
echo "| EXPECTED OUTPUT: $EXPECTED           "
echo "| ACTUAL OUTPUT: ${RESULT/$'\n'/}      "
echo "+--------------------------------------"
echo "|               TEST CASE: $CASESTATUS "
echo "+--------------------------------------"
echo ""

# Test Case 7
INPUT="80 80"
EXPECTED="Pass"
RESULT=`java -jar $GRADESFILE $INPUT`
if [ "$EXPECTED" == "$RESULT" ]; then
    CASESTATUS="Passed."
else
    CASESTATUS="Failed."
fi

echo "+--------------------------------------"
echo "| TEST CASE SEVEN - COMBINED = 80      "
echo "+--------------------------------------"
echo "| INPUT: $INPUT                        "
echo "| EXPECTED OUTPUT: $EXPECTED           "
echo "| ACTUAL OUTPUT: ${RESULT/$'\n'/}      "
echo "+--------------------------------------"
echo "|               TEST CASE: $CASESTATUS "
echo "+--------------------------------------"
echo ""

# Test Case 8
INPUT="100 100"
EXPECTED="Pass"
RESULT=`java -jar $GRADESFILE $INPUT`
if [ "$EXPECTED" == "$RESULT" ]; then
    CASESTATUS="Passed."
else
    CASESTATUS="Failed."
fi

echo "+--------------------------------------"
echo "| TEST CASE EIGHT - COMBINED = 100     "
echo "+--------------------------------------"
echo "| INPUT: $INPUT                        "
echo "| EXPECTED OUTPUT: $EXPECTED           "
echo "| ACTUAL OUTPUT: ${RESULT/$'\n'/}      "
echo "+--------------------------------------"
echo "|               TEST CASE: $CASESTATUS "
echo "+--------------------------------------"
echo ""

# Test Case 9
INPUT="1000 1000"
EXPECTED="Invalid Input"
RESULT=`java -jar $GRADESFILE $INPUT`
if [ "$EXPECTED" == "$RESULT" ]; then
    CASESTATUS="Passed."
else
    CASESTATUS="Failed."
fi

echo "+--------------------------------------"
echo "| TEST CASE NINE - INVALID INPUT 1000  "
echo "+--------------------------------------"
echo "| INPUT: $INPUT                        "
echo "| EXPECTED OUTPUT: $EXPECTED           "
echo "| ACTUAL OUTPUT: ${RESULT/$'\n'/}      "
echo "+--------------------------------------"
echo "|               TEST CASE: $CASESTATUS "
echo "+--------------------------------------"
echo ""

# Test Case 10
INPUT="A B"
EXPECTED="Invalid Input"
RESULT=`java -jar $GRADESFILE $INPUT`
if [ "$EXPECTED" == "$RESULT" ]; then
    CASESTATUS="Passed."
else
    CASESTATUS="Failed."
fi

echo "+--------------------------------------"
echo "| TEST CASE TEN - INVALID INPUT A B    "
echo "+--------------------------------------"
echo "| INPUT: $INPUT                        "
echo "| EXPECTED OUTPUT: $EXPECTED           "
echo "| ACTUAL OUTPUT: ${RESULT/$'\n'/}      "
echo "+--------------------------------------"
echo "|               TEST CASE: $CASESTATUS "
echo "+--------------------------------------"
echo ""

# Test Case 11
INPUT=""
EXPECTED="Invalid Input"
RESULT=`java -jar $GRADESFILE $INPUT`
if [ "$EXPECTED" == "$RESULT" ]; then
    CASESTATUS="Passed."
else
    CASESTATUS="Failed."
fi

echo "+--------------------------------------"
echo "| TEST CASE ELEVEN - INVALID INPUT (NULL)"
echo "+--------------------------------------"
echo "| INPUT: $INPUT                        "
echo "| EXPECTED OUTPUT: $EXPECTED           "
echo "| ACTUAL OUTPUT: ${RESULT/$'\n'/}      "
echo "+--------------------------------------"
echo "|               TEST CASE: $CASESTATUS "
echo "+--------------------------------------"
echo ""
